#include "UcsHandler.h"
#include "CmdManager.h"
#include "Scene.h"
#include "QtOSGWidget.h"
#include "Manipulator/SwitchViewManipulator.h"

UcsHandler::UcsHandler()
{
}

UcsHandler::~UcsHandler()
{
}

void UcsHandler::input(const QVariant& data, const QString& rawInput, CommandSource cs)
{
	if (data.type() == QVariant::Bool && !data.toBool())
	{
		emit finished();
		return;
	}

	if (status() == 0)
	{
		prompt(1, tr("指定UCS[XOY(z)/YOZ(x)/XOZ(y)]:"));
		return;
	}

	if (status() == 1)
	{
		auto scene = getScene();
		if(rawInput == QString("z"))
			scene->setCurrentUCS(UCSKind::XOY);
		else if (rawInput == QString("x"))
			scene->setCurrentUCS(UCSKind::YOZ);
		else if (rawInput == QString("y"))
			scene->setCurrentUCS(UCSKind::ZOX);
		emit finished();
	}
	return;
}

/////////////////WorkPlaneHandler////////////////////////
WorkPlaneHandler::WorkPlaneHandler()
{
}

WorkPlaneHandler::~WorkPlaneHandler()
{
}

void WorkPlaneHandler::input(const QVariant& data, const QString& rawInput, CommandSource cs)
{
	if (data.type() == QVariant::Bool && !data.toBool())
	{
		emit finished();
		return;
	}

	if (status() == 0)
	{
		prompt(1, tr("指定工作平面[XOY(z)/YOZ(x)/XOZ(y)]:"));
		return;
	}

	if (status() == 1)
	{
		auto widget3D = getWidget();
		auto scene = getScene();
		if (rawInput == QString("z"))
		{
			scene->setCurrentUCS(UCSKind::XOY);
			widget3D->switchProjection(false);
			widget3D->setView(SwitchView::Z);
		}
		else if (rawInput == QString("x"))
		{
			scene->setCurrentUCS(UCSKind::YOZ);
			widget3D->switchProjection(false);
			widget3D->setView(SwitchView::X);
		}
		else if (rawInput == QString("y"))
		{
			scene->setCurrentUCS(UCSKind::ZOX);
			widget3D->switchProjection(false);
			widget3D->setView(SwitchView::NY);
		}
		emit finished();
	}
	return;
}
